package com.dk.base.core.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Slf4j
@Component
public class MsgListener {

    @Autowired
    private ObjectMapper objectMapper;

    @SneakyThrows
    @KafkaListener(topics = "${shared.topic}", groupId = "base")
    public void consumerListener(ConsumerRecord<byte[], byte[]> record) throws IOException {
        Map map = objectMapper.readValue(record.value(), Map.class);
        System.out.println(map);
    }
}
